package cn.Liujialin.basic.controller;

import cn.Liujialin.basic.service.IVerifyCodeService;
import cn.Liujialin.basic.util.AjaxResult;
import cn.Liujialin.cation.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    // 发送验证码接口

    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody Map<String,String> param){
        try {
            String phone = param.get("phone");
            String type = param.get("type");
            verifyCodeService.smsCode(param);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.fail("发送验证码失败！");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("後端出錯誤了");
        }
    }
}
